install.packages("GeoLight")
library(GeoLight)
library(GeoLight)
correct_decim <- function(x)as.numeric(gsub(",", ".", x, fixed = TRUE))
filename<-("C:/Users/helgason/Dropbox/GSdata/SEATRACK/ForHallvard/ForSebastien/C65_F027_140901_124029.lux")
tab2 <- luxTrans(filename)
tab2$light<-correct_decim(tab2$light)
tab3<-twilightCalc(tab2$datetime, tab2$light,LightThreshold=16,preSelection=TRUE,maxLight=5,ask=FALSE,nsee=1500,allTwilights=FALSE)
attach(tab3)
coord <- coord(tFirst,tSecond,type,degElevation=-3,site=FALSE,sites,note=TRUE)
filter <- distanceFilter(tFirst,tSecond,type,distance=30)
tripMap(coord[filter,],equinox=FALSE,xlim=c(-60,40),ylim=c(50,90),main="Sebastien - F627")
tab3<-twilightCalc(tab2$datetime, tab2$light,LightThreshold=16,preSelection=TRUE,maxLight=5,ask=TRUE,nsee=1500,allTwilights=FALSE)
install.packages(pkgs = c("adehabitatHR", "rgdal", "sp", "dismo", "raster"), repos="http://cran.uib.no/")
Sys.Date()#Hvada dagur i tølvunni
Sys.time()#hvad er klukkan i tølvunni
Sys.timezone()#Hvada timezone er klukkan i tølvunni
now<-Sys.time()
format(now, "%d/%m/y")
format(now, "%d/%m/%y")
format(now, "%B")
strptime
?strptime
date1 <- "12/30/2006 10:34" # Example of a timestamp you could find in a dataset
date2 <- "02/15/2007 14:45"
class(date1)
difftime(date2, date1)
date1 <- strptime(date1, format = "%m/%d/%Y %H:%S")
date2 <- strptime(date2, format = "%m/%d/%Y %H:%S")
date1 <- strptime(date1, format = "%m/%d/%Y %H:%S")
date2 <- strptime(date2, format = "%m/%d/%Y %H:%S")
difftime(date2, date1)
date1 <- "12/30/2006 10:34" # Example of a timestamp you could find in a dataset
date2 <- "02/15/2007 14:45"
date1 <- strptime(date1, format = "%m/%d/%Y %H:%S")
date2 <- strptime(date2, format = "%m/%d/%Y %H:%S")
difftime(date2, date1)
date1; date2 # Take a look
difftime(date2, date1, units = "days"") # Now that works
difftime(date2, date1, units = "days") # Now that works
difftime(date2, date1, units = "days") # Now that works
difftime(date2, date1, units = "hours")
source('C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/R_workshop_spatial_analysis1.R')
library(adehabitatHR); library(rgdal); library(sp);
library(dismo); library(raster); library(plotKML)
install.packages(pkgs = c(plotKML, repos="http://cran.uib.no/")
)
install.packages(plotKML, repos="http://cran.uib.no/")
install.packages("plotKML")
install.packages("plotKML")
dat.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data"       # another way to do it: choose.dir(getwd(), "Choose the folder containing the datafiles")
shp.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/shapefiles"  # choose.dir(getwd(), "Choose the folder containing the shapefiles")
out.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/outputs"    # choose.dir(getwd(), "Choose the folder where your outputs will be saved")
fun.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/functions"  # choose.dir(getwd(), "Choose the folder containing the functions")
source(paste(fun.dir, "/FUNCTION_Add_UTM_Grid_to_rgdal::projected_Map.r", sep = ""))
source(paste(fun.dir, "/FUNCTION_Add_UTM_Grid_to_projected_Map.r", sep = ""))
fun.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/functions"  # choose.dir(getwd(), "Choose the folder containing the functions")
source(paste(fun.dir, "/FUNCTION_Add_UTM_Grid_to_projected_Map.r", sep = ""))
fun.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/functions"  # choose.dir(getwd(), "Choose the folder containing the functions")
source(paste(fun.dir, "/FUNCTION_Add_UTM_Grid_to_projected_Map.r", sep = ""))
fun.dir <- "functions"
out.dir <- "outputs"
shp.dir <- "data/shapefiles"
dat.dir <- "data"
source(paste(fun.dir, "/FUNCTION_Add_UTM_Grid_to_projected_Map.r", sep = ""))
proj.fox  <- "+proj=utm +zone=33N +lon_0=15 +datum=WGS84"
fun.dir <- "functions"
proj.fox  <- "+proj=utm +zone=33N +lon_0=15 +datum=WGS84"
SvalLR  <- readOGR(dsn = shp.dir, layer="S5000_Land_f_pr") # Low resolution version (faster to draw maps)
shp.dir <- "data/shapefiles"
SvalLR  <- readOGR(dsn = shp.dir, layer="S5000_Land_f_pr") # Low resolution version (faster to draw maps)
#shp.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/shapefiles"  # choose.dir(getwd(), "Choose the folder containing the shapefiles")
shp.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data/shapefiles"  # choose.dir(getwd(), "Choose the folder containing the shapefiles")
SvalLR  <- readOGR(dsn = shp.dir, layer="S5000_Land_f_pr") # Low resolution version (faster to draw maps)
SvalHR  <- readOGR(dsn = shp.dir, layer="S250_Land_f")     # Higher resolution version (for publication and such)
Koter   <- readOGR(dsn = shp.dir, layer="S1000_Koter_l")   # Contour lines (isopleths) join points of same alti.
SvalLR
class(SvalLR)
is.rgdal::projected(SvalLR)
projected(SvalLR)
?SpatialPolygonsDataFrame
is.projected(SvalLR)
summary(SvalLR)
str(SvalLR)
str(SvalLR, max.level = 2)
proj4string(SvalLR) # The information is contained in a text string
plot(SvalLR, col = "#FF00E1", border = "#00FFC8", lwd = 2)
data.raw <- read.delim(paste(dat.dir, "/Lab02_Argos_Fox_Raw.txt", sep = ""), header = TRUE, sep = "\t")
dat.dir <- "C:/Users/helgason/Dropbox (SEATRACK)/HalfdansWorkfiles/Rworkshops/Spatial analysis/Spatial_Analysis_1/data"       # another way to do it: choose.dir(getwd(), "Choose the folder containing the datafiles")
data.raw <- read.delim(paste(dat.dir, "/Lab02_Argos_Fox_Raw.txt", sep = ""), header = TRUE, sep = "\t")
summary(data.raw$Fox_Id)
View(data.raw)
data <- read.delim(paste(dat.dir, "/Lab02_Argos_Fox_Filtered.txt", sep = ""), header=TRUE, sep="\t")
View(data)
strptime(data$Loc_Date, "%Y-%m-%d %T", tz="GMT")[1:10] # Does this look OK?
data$date   <-  strptime(data$Loc_Date, "%Y-%m-%d %T", tz="GMT")
data$year      <- as.factor(format(data$date, "%Y"))
data$day       <- format(data$date, "%Y-%m-%d")
data$ID_Season <- as.factor(paste(formatC(data$Fox_ID, width = 3, format = "d", flag = "0") ,
format(data$date, "%Y-%m"), sep="_"))
data$ID_Year   <- as.factor(paste(formatC(data$Fox_ID, width = 3, format = "d", flag = "0") , format(data$date, "%Y"), sep="_"))
par(mfrow=c(1,2))
plot(data$Longitude ~ data$Fox_ID, xlab = "Fox ID", ylab = "Longitude")
plot(data$Longitude ~ as.factor(data$Fox_ID), xlab = "Fox ID", ylab = "Longitude")
class(data$Fox_ID)
data$Fox_ID <- as.factor(data$Fox_ID)
class(data$Fox_ID)
range(data$Longitude)
range(data$Latitude)
xy_proj       <- project(cbind(data$Longitude, data$Latitude), proj = proj.fox)
data$Easting  <- xy_proj[,1] ## N.B. Easting is the rgdal::projected Longitude
data$Northing <- xy_proj[,2] ## N.B. Northing is the rgdal::projected Latitude
par(mfrow=c(1,2), mar = c(3,3,3,3), mgp = c(1,.2,0)) # Defining the plotting parameters
plot(SvalLR, col = "lightgray")
points(data$Easting, data$Northing, pch = 1, cex = .5, col = "red") # Adding the locations
zoom.area <- drawExtent(col = "blue")
plot(SvalLR, col = "white", asp=1, xlim=c(zoom.area@xmin, zoom.area@xmax), ylim=c(slot(zoom.area, 'ymin'), slot(zoom.area, 'ymax')))
points(data$Easting, data$Northing, pch = 1, cex = .5, col = "red")
box()
for (i in 1:4){
axis(i, cex = .1, tcl = .4)
}
zoom.area <- drawExtent(col = "blue")
plot(SvalLR, col = "white", asp=1, xlim=c(zoom.area@xmin, zoom.area@xmax), ylim=c(slot(zoom.area, 'ymin'), slot(zoom.area, 'ymax')))
points(data$Easting, data$Northing, pch = 1, cex = .5, col = "red")
box()
for (i in 1:4){
par(mfrow=c(1,2), mar = c(3,3,3,3), mgp = c(1,.2,0)) # Defining the plotting parameters
plot(SvalLR, col = "lightgray")
points(data$Easting, data$Northing, pch = 1, cex = .5, col = "red") # Adding the locations
par(mfrow=c(1,2), mar = c(3,3,3,3), mgp = c(1,.2,0)) # Defining the plotting parameters
plot(SvalLR, col = "lightgray")
points(data$Easting, data$Northing, pch = 1, cex = .5, col = "red") # Adding the locations
zoom.area <- drawExtent(col = "blue")
plot(SvalLR, col = "white", asp=1, xlim=c(zoom.area@xmin, zoom.area@xmax), ylim=c(slot(zoom.area, 'ymin'), slot(zoom.area, 'ymax')))
points(data$Easting, data$Northing, pch = 1, cex = .5, col = "red")
box()
for (i in 1:4){
axis(i, cex = .1, tcl = .4)
}
plot(Koter, add = TRUE, col = "lightgray")
par(mfrow=c(1,2), mar = c(3,3,3,3), mgp = c(1,.2,0)) # Defining the plotting parameters
plot(SvalLR, asp=1, ylim = c(8500000, 9000000))
cols <- c("#1344D630", "#DE430030", "#0C940030") # These are 'hexadecimal' colour codes
for (i in 1:length(unique(data$Fox_ID))){
tmp <- subset(data, Fox_ID == unique(data$Fox_ID)[i])
points(tmp$Easting, tmp$Northing, pch = 16, cex = .6, col = cols[i])
rm(tmp)
}
box()
for (i in 1:4) axis(i, cex.axis = .8, tcl = .4, mgp = c(1, .2,0))
options(scipen=999)
for (i in 1:4) axis(i, cex.axis = .8, tcl = .4, mgp = c(1, .2,0))
abline(h = seq(8500000, 9000000, 100000), v = seq(200000, 1000000, 100000), col = "#00000030", lty = 3)
plot(SvalLR, asp=1, ylim = c(8500000, 9000000))
# now we will define a different colour for each individual
cols <- c("#1344D630", "#DE430030", "#0C940030") # These are 'hexadecimal' colour codes
# check     www.colorpicker.com     to obtain easily this code for any colour
#***************************************************************************************************************
# NB1: hex colour codes in R must be preceded by a hash sign (#)
# NB2: hex colour code contain 6 characters/digits only
# NB3: you can add to digits atthe end of the 6-character colour code:
#      this will define the level of opacity (transparency), from 0% ('00') to 99% ('99'). For 100%, use 'FF'
#***************************************************************************************************************
for (i in 1:length(unique(data$Fox_ID))){
tmp <- subset(data, Fox_ID == unique(data$Fox_ID)[i])
points(tmp$Easting, tmp$Northing, pch = 16, cex = .6, col = cols[i])
rm(tmp)
}
box()
for (i in 1:4) axis(i, cex.axis = .8, tcl = .4, mgp = c(1, .2,0))
# Not really nice axis labels
# We can change the options to avoid using the Scientific Notation
options(scipen=999)
# Let's try again
for (i in 1:4) axis(i, cex.axis = .8, tcl = .4, mgp = c(1, .2,0))
# You can add a simple UTM graticule
abline(h = seq(8500000, 9000000, 100000), v = seq(200000, 1000000, 100000), col = "#00000030", lty = 3)
# you can create a new map with a lat/lon graticule
plot(SvalHR, col = "lightgray", bg = "#10698760", asp=1, ylim = c(8500000, 9000000))
cols <- c("#1344D630", "#DE430030", "#0C940030") # Define a vector of 3 colours, one per individual
# Loop on each individual to plot the locations
for (i in 1:length(unique(data$Fox_ID))){
tmp <- subset(data, Fox_ID == unique(data$Fox_ID)[i])
points(tmp$Easting, tmp$Northing, pch = 16, cex = .6, col = cols[i])
rm(tmp)
}
box()
# Add properly labeled axes
for (i in 1:4) axis(i, cex.axis = .8, tcl = .4, mgp = c(1, .2,0))
# Add the graticule
UTMGrid(grid.col="#33333380", txt.col="white", prj = proj.fox, txt.size = 1, txt.font = 2,
parl = seq(75, 85, 1), parl.extent = seq(-10, 60, .01), parl.lab.long = 27.5, parl.lab.offset = 0,
merid = seq(-10, 50, 5), mer.extent = seq(75, 85,.01), mer.lab.lat = 76.6)
box()
TF <- setwd('C:/Users/helgason/Desktop/LBBG_2015_DEL/L205_2015_c250')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
library(GeoLight)
TF <- setwd('C:/Users/helgason/Desktop/LBBG_2015_DEL/L205_2015_c250')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
summary(trn2$month)
cols <- NULL
cols[trn2$month == "1"] <- "cyan1"
cols[trn2$month == "2"] <- "turquoise1"
cols[trn2$month == "3"] <- "navy"
cols[trn2$month == "4"] <- "lawngreen"
cols[trn2$month == "5"] <- "limegreen"
cols[trn2$month == "6"] <- "seagreen"
cols[trn2$month == "7"] <- "red"
cols[trn2$month == "8"] <- "red4"
cols[trn2$month == "9"] <- "orange"
cols[trn2$month == "10"] <- "violet"
cols[trn2$month == "11"] <- "hotpink"
cols[trn2$month == "12"] <- "plum"
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(40,70),xlim=c(-25,20),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(40,70),xlim=c(-25,20),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(10, 70,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
TF <- setwd('C:/Users/helgason/Desktop/LBBG_2015_DEL/L226_2015_c250')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
TF <- setwd('C:/Users/helgason/Desktop/LBBG_2015_DEL/L226_2015_c250')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
#TF <- setwd('C:/Users/helgason/Dropbox (SEATRACK)/Locations and data/Franz Josef Land/LAHYP')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
summary(trn2$month)
cols <- NULL
cols[trn2$month == "1"] <- "cyan1"
cols[trn2$month == "2"] <- "turquoise1"
cols[trn2$month == "3"] <- "navy"
cols[trn2$month == "4"] <- "lawngreen"
cols[trn2$month == "5"] <- "limegreen"
cols[trn2$month == "6"] <- "seagreen"
cols[trn2$month == "7"] <- "red"
cols[trn2$month == "8"] <- "red4"
cols[trn2$month == "9"] <- "orange"
cols[trn2$month == "10"] <- "violet"
cols[trn2$month == "11"] <- "hotpink"
cols[trn2$month == "12"] <- "plum"
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
TF <- setwd('C:/Users/helgason/Dropbox (SEATRACK)/Locations and data/Bjornoya/not processed loggers_Bjornoya/Great_skua_2016/Q540_2016_C250')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
cols <- NULL
cols[trn2$month == "1"] <- "cyan1"
cols[trn2$month == "2"] <- "turquoise1"
cols[trn2$month == "3"] <- "navy"
cols[trn2$month == "4"] <- "lawngreen"
cols[trn2$month == "5"] <- "limegreen"
cols[trn2$month == "6"] <- "seagreen"
cols[trn2$month == "7"] <- "red"
cols[trn2$month == "8"] <- "red4"
cols[trn2$month == "9"] <- "orange"
cols[trn2$month == "10"] <- "violet"
cols[trn2$month == "11"] <- "hotpink"
cols[trn2$month == "12"] <- "plum"
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
TF <- setwd('C:/Users/helgason/Dropbox (SEATRACK)/Locations and data/Bjornoya/not processed loggers_Bjornoya/Great_skua_2016/Q540_2016_C250')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
summary(trn2$month)
cols <- NULL
cols[trn2$month == "1"] <- "cyan1"
cols[trn2$month == "2"] <- "turquoise1"
cols[trn2$month == "3"] <- "navy"
cols[trn2$month == "4"] <- "lawngreen"
cols[trn2$month == "5"] <- "limegreen"
cols[trn2$month == "6"] <- "seagreen"
cols[trn2$month == "7"] <- "red"
cols[trn2$month == "8"] <- "red4"
cols[trn2$month == "9"] <- "orange"
cols[trn2$month == "10"] <- "violet"
cols[trn2$month == "11"] <- "hotpink"
cols[trn2$month == "12"] <- "plum"
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
TF <- setwd('C:/Users/helgason/Dropbox (SEATRACK)/Locations and data/Bjornoya/not processed loggers_Bjornoya/Great_skua_2016/Q541_2016_C250')
TF <- setwd('C:/Users/helgason/Dropbox (SEATRACK)/Locations and data/Bjornoya/not processed loggers_Bjornoya/Great_skua_2016/Q541_15aug16_115826')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
summary(trn2$month)
cols <- NULL
cols[trn2$month == "1"] <- "cyan1"
cols[trn2$month == "2"] <- "turquoise1"
cols[trn2$month == "3"] <- "navy"
cols[trn2$month == "4"] <- "lawngreen"
cols[trn2$month == "5"] <- "limegreen"
cols[trn2$month == "6"] <- "seagreen"
cols[trn2$month == "7"] <- "red"
cols[trn2$month == "8"] <- "red4"
cols[trn2$month == "9"] <- "orange"
cols[trn2$month == "10"] <- "violet"
cols[trn2$month == "11"] <- "hotpink"
cols[trn2$month == "12"] <- "plum"
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
TF <- setwd('C:/Users/helgason/Dropbox (SEATRACK)/Locations and data/Bjornoya/not processed loggers_Bjornoya/Great_skua_2016/Q541_15aug16_115826')
sources.lux  <- list.files(path=TF,recursive=F,pattern='*.lux$',full.names=F)
lux        <- read.table(paste(TF,sources.lux[1],sep="/"),skip=19,header=T,sep=",")
lux$lux    <- as.numeric(as.character(substr(lux[,1],22,50)))
lux$time   <- as.POSIXct(strptime(substr(lux[,1],1,19),format="%d/%m/%Y %H:%M:%S"),tz="UTC")
lux        <- lux[!is.na(lux$lux),]
trn        <- twilightCalc(lux$time,lux$lux,ask=F)
trn$dtime  <- (trn$tSecond-trn$tFirst)/2 + trn$tFirst
trn$lon    <- coord(trn,degElevation=-3,note=F)[,1]
trn$lat    <- coord(trn,degElevation=-3,note=F)[,2]
trn$jday   <- floor(round(as.numeric(julian(trn$dtime)),digits=2))
trn$year   <- as.numeric(strftime(trn$dtime, format = "%Y"))
trn$month  <- as.numeric(strftime(trn$dtime, format = "%m"))
trn$doy    <- floor(as.numeric(strftime(trn$dtime, format = "%j")))
trn2       <- trn[trn$doy %in% c(1:57,91:246,284:366),]
summary(trn2$month)
cols <- NULL
cols[trn2$month == "1"] <- "cyan1"
cols[trn2$month == "2"] <- "turquoise1"
cols[trn2$month == "3"] <- "navy"
cols[trn2$month == "4"] <- "lawngreen"
cols[trn2$month == "5"] <- "limegreen"
cols[trn2$month == "6"] <- "seagreen"
cols[trn2$month == "7"] <- "red"
cols[trn2$month == "8"] <- "red4"
cols[trn2$month == "9"] <- "orange"
cols[trn2$month == "10"] <- "violet"
cols[trn2$month == "11"] <- "hotpink"
cols[trn2$month == "12"] <- "plum"
trn2$cols <- cols
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=21,bg=rgb(1,0,0,0.2),col=rgb(1,0,0,0),asp=1)
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
function (x, y = NULL, legend, fill = NULL, col = par("col"),
map('world',add=T)
plot(trn2$lon,trn2$lat,ylim=c(00,90),xlim=c(-50,55),cex=1,pch=18,bg=rgb(1,0,0,0.2),col=(trn2$cols),asp=1)
legend(50, 85,unique(trn2$month), col = unique(cols), pch = 18, bg = "gray90")
map('world',add=T)
